
import 'package:distribution_mall_flutter/pages/merchant_authentication/domain/merchant_auth_last_entity.dart';
import 'package:image_picker/image_picker.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import 'state/merchant_authentication_state.dart';

part 'merchant_authentication_provider.g.dart';

@riverpod
class MerchantAuthentication extends _$MerchantAuthentication {
  @override
  MerchantAuthenticationState build() {
    return MerchantAuthenticationState();
  }

  void setNewData(MerchantAuthLastBody? data) {
    state = state.copyWith(merchantAuthLastBody: data, loadSuccess: true);
    if (data != null) {
      state.businessNameController.text = data.businessName!;
      state.phoneNumberController.text =
          data.phoneNumber!.callingNumber!.toString();
      state.certificateNoController.text = data.certificateNo!;
      if(data.address != null){
        state.addressController.text = [data.address!.province,data.address!.city,data.address!.district,data.address!.street,].join('/');
        state.addressDetailController.text = data.address!.detailed;
      }
    }
  }
}

@riverpod
class MerchantAuthenticationSelectImageFile
    extends _$MerchantAuthenticationSelectImageFile {
  @override
  XFile? build() {
    return null;
  }

  void setNewData(XFile? data) {
    state = data;
  }
}

@riverpod
class MerchantAuthenticationSelectImageFileShowError
    extends _$MerchantAuthenticationSelectImageFileShowError {
  @override
  bool build() {
    return false;
  }

  void setError(bool data) {
    state = data;
  }
}
